﻿using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Description;

namespace Learun.Application.Web.AppApi
{
    /// <summary>
    /// 项目接口
    /// </summary>
    [RoutePrefix("api/ProjectApi")]
    //[HandlerApiLogin(FilterMode.Enforce)]
    //[TokenAuthorize]
    public class ProjectApiController : WebApiControllerBase
    {
        /// <summary>
        /// 获取项目
        /// </summary>
        /// <param name="pageNo">当前页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(List<ec_projectEntity>))]
        public IHttpActionResult GetProjectSelectPageList(int pageNo, int pageSize)
        {
            try
            {
                ec_projectIBLL ec_projectIBLL = new ec_projectBLL();

                string queryJson = "{}";
                Pagination paginationobj = new Pagination();
                paginationobj.page = pageNo;
                paginationobj.rows = pageSize;
                paginationobj.sidx = "CreateTime ";
                paginationobj.sord = "DESC";
                paginationobj.records = 0;

                var data = ec_projectIBLL.GetProjectSelectPageList(paginationobj, queryJson);
                var jsonData = new
                {
                    rows = data,
                    total = paginationobj.total,
                    records = paginationobj.records
                };
                return Success(jsonData);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        /// <summary>
        /// 2023 07 31，插件端选择项目后，统一、整合加载左侧面板里的数据（By YUXH）
        /// </summary>
        /// <param name="ProjId"></param>
        /// <param name="User">当前用户</param>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult InitProjInfo(string ProjId, string User)
        {
            var drawingCategoryBll = new ec_drawing_catalogueBLL();
            var templateCategoryBll = new ec_template_catalogueBLL();
            var objectTypeBll = new ec_objecttypeBLL();
            var NotificationBll = new ec_notificationBLL();
            #region 获取图纸目录DrawingFileApi/GetDrawingCatalogue
            var res1 = drawingCategoryBll.GetDrawingCategory(ProjId, "0");
            #endregion
            #region DrawingFileApi/GetDrawingCatalogueByType
            var res2 = drawingCategoryBll.GetDrawingCategoryByType(ProjId);
            #endregion
            #region DrawingFileApi/GetDrawingCatalogueBySystem
            var res3 = drawingCategoryBll.GetDrawingCatalogueBySystem(ProjId);
            #endregion
            #region TemplateFileApi/GetTemplateCatalogue
            var res4 = templateCategoryBll.GetTemplateCategory(ProjId);
            #endregion
            #region ObjectTypeApi/GetObjectTypeData0
            var res5 = objectTypeBll.GetObjectTypeData3Level(ProjId, "0");
            #endregion
            #region ObjectTypeApi/GetObjectTypeData2
            // 这个数据量太大，导致加载项目时卡顿长达6分钟，所以单独独立出去
            // var res6 = objectTypeBll.GetObjectTypeData3Level(ProjId, "2");
            #endregion
            #region NotificationApi/GetUserAllNotification
            var res7 = NotificationBll.GetUserAllNotification(ProjId, User);
            #endregion
            var resAll = new List<object>
            {
                new { Name = "图纸树（按目录）", data = res1 },
                new { Name = "图纸树（按类型）", data = res2 },
                new { Name = "图纸树（按系统）", data = res3 },
                new { Name = "样板文件树", data = res4 },
                new { Name = "对象类型树", data = res5 },
                new { Name = "对象类型树（带位号和图纸信息）", data ="后续独立查询" },
                new { Name = "通知", data = res7 }
            };

            //var resAll = new List<List<TreeModel>>
            //{
            //    res1, res2,res3,res4,res5,res6,res7
            //};

            return Success(resAll);
        }
    }
}